<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Wangwangmag extends CI_Controller {

    public function __construct() {
        parent::__construct();
        $this->load->helper('url');
        $this->load->helper('fuc');
        $this->load->helper('file');
        $this->load->library('topclass');
        $this->load->database();
        $this->load->helper('form');
        $this->load->model('service');
        $this->load->model('memmbers');
        if (!isset($_SESSION["statue"])) {
            $url = site_url("login/index");
            redirect($url, 'location');
        }
        
decis_last_time();
    }

    public function index() {

        print_r($this->service->import_data_new());
        $this->load->view('welcome_message');
    }

    /*     * ****************************************************************
     *  设置旺旺分类
     */

    public function wwset() {

        $data['menu'] = 'wwset';
        $data['userleve'] = $this->memmbers->get_user_level();
        $data['grouparray'] = $this->service->get_group_array($_SESSION["shopid"]);

        $data['clientsarray'] = $this->service->get_childaccount($_SESSION["shopid"]);
        if (!$data['clientsarray']) {
//            echo "<script    language=\"javascript\">
//alert(\"您的淘宝子帐号还未设置请设置后使用此功能\");
//</script>";
        }

        $data['sellerinfo'] = $this->service->get_seller_info($_SESSION["shopid"]);

        $this->load->view('header_view', $data);
        $this->load->view('wwset_view');
        $this->load->view('footer_view');
    }

    public function delclient() {
        if ($this->uri->segment(3) === FALSE) {
            $id = 0;
            redirect("wangwangmag/wwset");
        } else {
            $id = $this->uri->segment(3);
               if (!is_numeric($id)) {
                redirect("wangwangmag/wwset");
            }
        }

        $this->service->delete_client($id);
        redirect("wangwangmag/wwset");
    }

    public function savegroup() {
        //print_r($_POST);
        if (!isset($_POST["groupName"])) {
            redirect("wangwangmag/wwset");
        }
        $this->service->save_role($_POST["groupName"]);
        redirect("wangwangmag/wwset");
    }

    public function updategroup() {
        //   print_r($_POST);
        if (!isset($_POST["groupId"])) {
            redirect("wangwangmag/wwset");
        }
        $this->service->update_role($_POST);
        redirect("wangwangmag/wwset");
    }

    public function delgroup() {
        if ($this->uri->segment(3) === FALSE) {
            $id = 0;
            redirect("wangwangmag/wwset");
          
        } else {
            $id = $this->uri->segment(3);
            if (!is_numeric($id)) {
                redirect("wangwangmag/wwset");
            }
        }
        $sql = "select * from client where shopid=\"{$_SESSION["shopid"]}\" and groupid=(select roleid
       from groups where id=\"{$id}\") ";
        $query = $this->db->query($sql);
        $res = $query->result_array();
        if (!empty($res)) {//不为空
            echo "<script language=\"JavaScript\" type=\"text/javascript\">alert(\"请先删除角色下面的子帐号再删除角色\");
        
</script>";


            //   exit;
        } else {
            $this->service->del_role($id);
        }

        redirect("wangwangmag/wwset");
    }

    public function saveclient() {
        //print_r($_POST);
        $this->service->save_client($_POST);

        redirect("wangwangmag/wwset");
    }

}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */